package com.zwr.sheller.customer.Service.Impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.zwr.sheller.core.pojo.Order;
import com.zwr.sheller.core.pojo.Refund;
import com.zwr.sheller.customer.Service.CustomerOrderService;
import com.zwr.sheller.customer.mapper.CustomerOrderMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * @Author LSY
 * @Date 2022/1/11 20:06
 * @Version 1.0
 **/
@Service
public class CustomerOrderServiceImpl implements CustomerOrderService {

    CustomerOrderMapper customerOrderMapper;
    @Autowired(required = false)
    public CustomerOrderServiceImpl(CustomerOrderMapper customerOrderMapper) {
        this.customerOrderMapper = customerOrderMapper;
    }

    @Override
    public PageInfo<Order> findAllOrders(Integer page, Integer num, Integer status, Long uid) {
        PageHelper.startPage(page, num);

        List<Order> orders = customerOrderMapper.findAllOrders(uid, status);
        for (Order order : orders) {
            order.setTotalMoney(customerOrderMapper.calculateTotalMoney(order.getOrderId()));
        }

        if(status != null && status == 5) {
            for (Order order : orders) {
                order.setRefund(customerOrderMapper.findRefundByOrderId(order.getOrderId()));
            }
        }
        return PageInfo.of(orders);
    }
}
